package com.yz.jdd.widget;

import android.app.Dialog;
import android.content.Context;
import android.text.Html;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.yz.jdd.R;


public class ProgressDialog extends Dialog {
	private ProgressBar progressBar;
	private TextView content;
	private TextView size;
	private Button hide;
	private Button cancel;
	
	public ProgressDialog(Context context) {
		super(context, R.style.Progress_Dialog);
//		activity=(Activity)context;
		setContentView(R.layout.dialog_download);
		progressBar=(ProgressBar)findViewById(R.id.progress_horizontal);
		content=(TextView)findViewById(R.id.content);
		size=(TextView)findViewById(R.id.size);
		getWindow().clearFlags(0x08000000);
	}
	
	public void setLeftButton(View.OnClickListener listener)
	{
			hide=(Button)findViewById(R.id.btn_ok);
			hide.setVisibility(View.VISIBLE);
			hide.setOnClickListener(listener);
	}
	
	public void setRightButton(View.OnClickListener listener)
	{
			cancel=(Button)findViewById(R.id.btn_cancel);
			cancel.setVisibility(View.VISIBLE);
			cancel.setOnClickListener(listener);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(keyCode== KeyEvent.KEYCODE_BACK)
		{
			this.dismiss();
		}
		return super.onKeyDown(keyCode, event);
	}
	
	public ProgressBar getProgressBar(){
		return progressBar;
	}
	
	public void setContent(String s){
		content.setText(s);
	}
	
	public void setDownSize(String currSize, String totalSize){
		size.setText(Html.fromHtml("<font color=\"#ff7800\">"+currSize+"</font>"+"/"+totalSize));
	}
}
